package com.example.qsindusty.jmm_spline.childactivity;

import android.text.TextUtils;

import com.example.qsindusty.jmm_spline.OrdeFragment.OrderData;
import com.example.qsindusty.jmm_spline.api.ApiManager;
import com.yixin.ystartlibrary.base.BasePresenter;
import com.yixin.ystartlibrary.base.IBaseView;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administration on 2018/4/9.
 */

public class ChildPrensenter extends BasePresenter implements  ChildContart.Presenter {
    ChildContart.View mView ;
    @Override
    public void bindView(IBaseView view) {
        mView= (ChildContart.View) view;
    }

    @Override
    public void unbindView() {
    dispose();
    }

    @Override
    public void getChildOrder(String token, String parentxh, String rows, String page) {
        ApiManager.getInstence().getJmmApi().getChildOrder(token,parentxh ,rows,page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<OrderData>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading();
                    }

                    @Override
                    public void onNext(OrderData orderData) {
                        if (TextUtils.equals(orderData.getStatus(),"0")){
                                if (orderData.getCount()!=0)
                                    mView.getSuccessful(orderData);
                                else
                                    mView.getNomore(orderData.getMessage());
                        }else {
                            mView.getFrailer(orderData.getMessage());
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.closeLoading();
                        mView.getFrailer(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.closeLoading();

                    }
                });
    }
}
